package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/findAll")
    public List<User> findAll(){

        return userService.findAll();
    }
    @RequestMapping("/getUser")
    public User getUser(@RequestParam("id") Integer id){
        return userService.getUserById(id);
    }
    @RequestMapping("/insert")
    public List<User> insert(User user){
        userService.insert(user);
        return userService.findAll();
    }
    @RequestMapping("/update")
    public List<User> update(User user){
        userService.update(user);
        return userService.findAll();
    }
    @RequestMapping("/delete")
    public int delete(@RequestParam("id") Integer id){
        return userService.delete(id);
    }
}
